package com.niiwoo.civet.trade.service.dubbo.guarantee;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.trade.dto.request.guarantee.GuaranteeRequestDTO;
import com.niiwoo.civet.trade.dto.response.guarantee.GuaranteeResponseDTO;
import com.niiwoo.civet.trade.service.guarantee.GuaranteeDubboService;
import com.niiwoo.civet.trade.service.local.guarantee.GuaranteeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.Optional;

/**
 * 担保dubbo服务实现
 *
 * @author liming
 * @date 2018-01-19 11:37
 */
@Slf4j
@Service(version = "1.0.0")
public class GuaranteeDubboServiceImpl implements GuaranteeDubboService{

    @Autowired
    private GuaranteeService guaranteeService;

    /**
     * 查询用户所有的担保记录数
     * @param requestDTO
     * @return
     */
    @Override
    public GuaranteeResponseDTO queryTotalGuaranteeNum(GuaranteeRequestDTO requestDTO) {
        if(!Optional.ofNullable(requestDTO).map(dto -> ObjectUtils.allNotNull(dto.getUserId(),dto.getType())).orElse(false)){
            log.error("GuaranteeDubboServiceImpl.queryTotalGuaranteeNum(GuaranteeRequestDTO) error,requestDTO: {}",requestDTO);
            GuaranteeResponseDTO responseDTO = new GuaranteeResponseDTO();
            responseDTO.setFailure();
            return responseDTO;
        }
        GuaranteeResponseDTO responseDTO = guaranteeService.queryTotalGuaranteeNum(requestDTO);
        responseDTO.setSuccess();
        return responseDTO;
    }
}
